﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SmartMathLibrary
{
    /// <summary>
    /// This class provides a translation matrix for four dimensional vectors. If a three dimensional
    /// vector should be transformed use for the fourth component(w) the value one.
    /// </summary>
    [Serializable]
    public class TranslationMatrix4D
    {
        /// <summary>
        /// The x translation of the translation matrix.
        /// </summary>
        private double xTranslation;

        /// <summary>
        /// The y translation of the translation matrix.
        /// </summary>
        private double yTranslation;

        /// <summary>
        /// The z translation of the translation matrix.
        /// </summary>
        private double zTranslation;

        /// <summary>
        /// Initializes a new instance of the <see cref="TranslationMatrix4D"/> class.
        /// </summary>
        /// <param name="translation">The translation value for x, y and z axis.</param>
        public TranslationMatrix4D(double translation)
        {
            this.xTranslation = translation;
            this.yTranslation = translation;
            this.zTranslation = translation;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="TranslationMatrix4D"/> class.
        /// </summary>
        /// <param name="xTranslation">The translation value for the x axis.</param>
        /// <param name="yTranslation">The translation value for the y axis.</param>
        /// <param name="zTranslation">The translation value for the z axis.</param>
        public TranslationMatrix4D(double xTranslation, double yTranslation, double zTranslation)
        {
            this.xTranslation = xTranslation;
            this.yTranslation = yTranslation;
            this.zTranslation = zTranslation;
        }

        /// <summary>
        /// Gets or sets the translation value for the x axis.
        /// </summary>
        /// <value>The translation value for the x axis.</value>
        public double XTranslation
        {
            get { return xTranslation; }
            set { xTranslation = value; }
        }

        /// <summary>
        /// Gets or sets the translation value for the y axis.
        /// </summary>
        /// <value>The translation value for the y axis.</value>
        public double YTranslation
        {
            get { return yTranslation; }
            set { yTranslation = value; }
        }

        /// <summary>
        /// Gets or sets the translation value for the z axis.
        /// </summary>
        /// <value>The translation value for the z axis.</value>
        public double ZTranslation
        {
            get { return zTranslation; }
            set { zTranslation = value; }
        }

        /// <summary>
        /// Gets the translation matrix for the transformation.
        /// </summary>
        /// <returns>The translation matrix for the transformation.</returns>
        public Matrix GetTranslationMatrix()
        {
            double[,] matrixData = new double[4,4];

            matrixData[0, 0] = 1;
            matrixData[0, 1] = 0;
            matrixData[0, 2] = 0;
            matrixData[0, 3] = this.xTranslation;

            matrixData[1, 0] = 0;
            matrixData[1, 1] = 1;
            matrixData[1, 2] = 0;
            matrixData[1, 3] = this.yTranslation;

            matrixData[2, 0] = 0;
            matrixData[2, 1] = 0;
            matrixData[2, 2] = 1;
            matrixData[2, 3] = this.zTranslation;

            matrixData[3, 0] = 0;
            matrixData[3, 1] = 0;
            matrixData[3, 2] = 0;
            matrixData[3, 3] = 1;

            return new Matrix(matrixData);
        }
    }
}